let app = getApp()
Component({ 
    properties: {
      infoArr: {
        type: Array,
        observer: function(newVal, oldVal) {
          this.updateRate()
        }
      }
      },
      data:{
        loginShow:false,
        popup: {
          tit: "请输入标签不超过10个字",
          btn: [ "取消", "确认" ],
          flag: !1,
          x: !1
      },
      params: {
        cus_id: "",
        tags: []
      }
      },
    lifetimes: {
        attached: function () {
 
         }
      },
    methods: {
      userinfo:function(e){
        var index=e.currentTarget.dataset.index
        var t=this.data.infoArr[index]
        var a = "/business-service/pages/staff_customer/customerInfo/index?imgUrl=" + encodeURIComponent(t.user_headimg) + "&name=" + t.nick_name + "&from=" + t.source + "&cus_id=" + t.cus_id + "&user_openid=" + t.openid + "&md5=" + t.md5 + "&phone=" + t.phone + "&user_id=" + t.user_id;
        wx.navigateTo({
          url:a
        })
      },
      editlabel:function(e){
        var index=e.currentTarget.dataset.index;
        var label=e.currentTarget.dataset.label;
        var custom=this.data.infoArr[index]
        var  popup={
          tit: "请编辑标签",
          btn: [ "取消", "确认" ],
          flag: !0,
          x: !1
       }
       this.setData({
           popup:popup,
           tags:e.currentTarget.dataset.label,
           old_tag:e.currentTarget.dataset.label,
           index:index
       })
      },
      addlabel:function(e){
        var index=e.currentTarget.dataset.index;
        var custom=this.data.infoArr[index]
        var  popup={
          tit: "请输入标签不超过10个字",
          btn: [ "取消", "确认" ],
          flag: !0,
          x: !1
       }
       this.setData({
           popup:popup,
           tags:'',
           old_tag:'',
           index:index
       })
      },
      callphone:function(e){
        var phone=e.currentTarget.dataset.phone;
        var that=this
        wx.request({
          url: app.globalData.siteroot,
           data: {
             do:'Message_getPushTmplIds',
             temp_name:'leave_message,place_order,visit_message'
          },
         success: function(res) {
            var leave_message=res.data.info.leave_message
            wx.requestSubscribeMessage({
                tmplIds: [leave_message],
                success (res) {
                  wx.showModal({
                    title: '是否要拨打这个电话？',
                    content:phone,
                    showCancel: true,
                    cancelText:"取消",
                    confirmText:"确定",
                    confirmColor: '#ff4040',
                    success: function (res) {
                      if (res.cancel) {
                      } else{
                        wx.makePhoneCall({
                          phoneNumber:phone,
                          success:function(){
                            console.log('拨打成功')
                          },
                          fail:function(){
                            console.log('拨打失败')
                          }
                        })
                      }
                     },
                     fail: function (res) { },
                     complete: function (res) { }
                })
                }
            })
         }
        })
      },
      updateRate:function(){},
      genjin:function(e){
        wx.showToast({
          title: '请先添加跟进记录！',
          icon: 'none',
          duration: 1500
        })
      },
      sendmsg:function(e){
        var index=e.currentTarget.dataset.index;
        var infoArr=this.data.infoArr
        var t=infoArr[index]
        wx.navigateTo({
          url: "/business-service/pages/staff_customer/sendmsg?id=" + t.user_id + "&cus_id=" + t.cus_id + "&imgUrl=" + encodeURIComponent(t.user_headimg) + "&name=" + t.nick_name + "&md5=" + t.md5 + "&from=" + t.source + "&user_openid=" + t.openid + "&is_intention=" + t.is_intention
        })
      },
      getPopupData:function(e){
        var index=this.data.index;
        var custom=this.data.infoArr[index]
        var that=this
        if(that.data.old_tag==''){
          wx.request({
            url: app.globalData.siteroot,
             data: {
               do:'Customer_addtag',
               staff_id:wx.getStorageSync('staff_bind_id'),
               cus_id:custom.cus_id,
               tags:e.detail,
               tag:''
            },
           success: function(res) {
             that.triggerEvent('changeTag',index)
           }
          })
        }else{
          wx.request({
            url: app.globalData.siteroot,
             data: {
               do:'Customer_editTag',
               staff_id:wx.getStorageSync('staff_bind_id'),
               cus_id:custom.cus_id,
               old_tag:that.data.old_tag,
               new_tag:e.detail
            },
           success: function(res) {
             that.triggerEvent('changeTag',index)
           }
          })
        }
       
      }
    }
});
